<?php
/**
 * Created by PhpStorm.
 * User: zhangbing
 * Date: 2017/5/20
 * Time: 16:16
 */
namespace app\admin\controller;
use app\models\Models;

class System extends Check{
    /**
     * 系统设置
     * @return array|\think\response\View
     */
    public function base(){
        $conf = new Models('config');
        // 获取配置文件信息
        $config = self::getConfig();
        if(request()->isPost()){
            $post = input('param.');
            foreach($post as $k=>$v){
                if($v != $config[$k]){
                    $conf->setValue(['key'=>$k],['value'=>$v]);
                }
            }
            // 添加操作日志
            self::addLog('修改系统设置');
            return self::formatSuccessResult();
        }
        return view('base',['config'=>$config]);
    }

    /**
     * 系统日志
     * @return \think\response\View
     */
    public function log(){
        $id  = cookie('join_login');
        $get = input('param.');
        $log = new Models('adminLog');
        // 条件查询
        $search = search($get,'a.log_action','a.log_time');
        $where  = $id > $log::GROUP_ADMIN ? $search['condition']." and a.id = $id" : $search['condition'];
        $list   = $log->_page($where,'a.*,b.username','a.id desc',[['admin b','a.uid = b.id','left']],$get['page'],15,$get);
        return view('log',['list'=>$list->items(),'page'=>$list->render(),'display'=>$search['display']]);
    }
}